# 1.从文件中读取内容，返回一个字符串 content
import os
import re

input_path = 'in.txt'
output_path = 'words.txt'

os.chdir(os.path.dirname(__file__))
with open(input_path) as file_obj:
    content = file_obj.read()
# print(content)

# 2.将 content 使用空格进行分隔，统一转化为小写，并对其按字典序排序
words = re.findall('[a-zA-Z]+',content)
# print(words)

word_list = set()

for i in words:
    word_list.add(i.lower())

ans = sorted(word_list)

# for j in ans:
#     print(j)

# 3.将content 放入到 hash 表中
# 4.输出 hash 表的内容即可
with open(output_path,'w') as file_obj :
    for j in ans:
        file_obj.writelines(j + '\n')